#下标，又称索引
str='0123456789'
print(str[0])
print(type(str[0]))

#切片语法：序列[开头位置：结尾位置：步长]  步长默认是1
str='0123456789'
print(str[0:7:1])
print(str[3:9:2])
print(str[3:9:-1])
print(str[9:3:-1])
print(str[9:])
print(str[:6:2])
print(str[::-1])
print(str[4::-1])
print(str[9:5:-2])
print(str[0::6])


#查找字符串，语法：字符串.find(子串，开始，结束位置)，找不到传-1
mystr="hello world and supertest and chenghao and Python"
print(mystr.find("and"))
print(mystr.find("ands"))
print(mystr.find("and",13,30))
#查找字符串，语法：字符串.index(子串，开始，结束位置),找不到则报错
mystr1="hello world and supertest and chenghao and Python"
print(mystr1.index("and"))
# print(mystr1.index("ands"))
print(mystr1.index("and",13,30))

#查找子串出现的次数，语法：字符串.count(子串，开始，结束位置),找不到返回0
print(mystr.count("and"))
print(mystr.count("ands"))
print(mystr.count("and",13,30))

#修改字符串语法：字符串.replace("旧串”,"新串",替换次数)
new_str=mystr.replace("and","or")
print(new_str)
new_str=mystr.replace("and","or",2)
print(new_str)
#字符串为不可变数据类型
print(mystr)
#分割字符串，语法：字符串.split(分割字符)  分割字符去掉不显示
new_str1="hello world and supertest and chenghao and Python"
print(new_str1.split("and"))
#字符串拼接：语法：拼接字符.join(要拼接的序列)
list1=['chao','ge','test','promotion']
tup1=('chao','ge','test','promotion')
str1=" ".join(list1)
print(str1)
print(type(str1))
print("-----".join(tup1))

#将首个字符串的首字母大写，其余字母小写
mystr="hello world and supertest and chenghao and Python"
print(mystr.capitalize())
#将每个字符串的首字母大写，其余字母小写
print(mystr.title())
#将每个字母都大写显示
print()

#去掉字符串两边指定字符
mystr="     hello world and supertest and chenghao and Python    "
print(mystr.strip())

